package hihocode;

import java.util.HashMap;
import java.util.Scanner;

public class Offer17Problem2 {

	private static final int MAX = 100002;
	
	private int[] array = new int[MAX];
	
	//数组重排
	public static void main(String[] args) {
		Offer17Problem2 object = new Offer17Problem2();
		object.getRes();
	}
	
	public void getRes(){
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()){
			int n = scanner.nextInt();
			int count = 0;
			HashMap<Integer, Integer> map = new HashMap<>(n);
			for(int i = 1; i <= n; i++){
				array[i] = scanner.nextInt();
				map.put(array[i], i);
			}
			for(int i = n; i > 1; i--){
				//获取数字i的index
				int index1 = map.get(i);
				int index2 = map.get(i - 1);
				//如果i - 1的下标位于i之前，那么就不用移动
				if(index2 < index1){
					continue;
				}
				map.put(i - 1, 0);
				count++;
			}
			System.out.println(count);
		}
		scanner.close();
	}
	
	//刚开始以为要移动数组，其实没必要，我们只需要改变map中的下标即可
	public void moveArray(int position){
	}
}
